﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_AgencyPhone
    {
    	#region public properties
		[Required(ErrorMessage="AgencyID Required")]
		public int AgencyID { get; set; }
		[Required(ErrorMessage="Phone Required")]
		public string Phone { get; set; }
		public bool? Disabled { get; set; }
		#endregion

		#region constructor
		public pa_AgencyPhone(){ }

		public pa_AgencyPhone(IDataReader rd)
		{
			this.AgencyID = (int)rd["AgencyID"];
			this.Phone = rd["Phone"].ToString();
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
		}
		#endregion

		#region private method
        public bool Create()
        {
            return DBpa_AgencyPhone.Create(AgencyID, Phone, Disabled);
        }

        public bool Update()
        {
            return DBpa_AgencyPhone.Update(AgencyID, Phone, Disabled);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(AgencyID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }

            if(Phone != string.Empty)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int AgencyID, string Phone)
        {
            return DBpa_AgencyPhone.Delete(AgencyID, Phone);
        }

        public static List<pa_AgencyPhone> GetAll()
        {
            return ObjectClass.CreateList<pa_AgencyPhone>(DBpa_AgencyPhone.GetAll());
        }

        public static pa_AgencyPhone GetByKey(int AgencyID, string Phone)
        {
            return ObjectClass.CreateInstance<pa_AgencyPhone>(DBpa_AgencyPhone.GetByKey(AgencyID, Phone));
        }

        public static List<pa_AgencyPhone> GetByForeignKeys(int AgencyID)
        {
            return ObjectClass.CreateList<pa_AgencyPhone>(DBpa_AgencyPhone.GetByForeignKeys(AgencyID));
        }

        public static List<pa_AgencyPhone> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_AgencyPhone>(DBpa_AgencyPhone.GetByTop(top, where, order));
        }
		#endregion
	}
}
